Skip to content

Conversation

@TomasVotruba
Copy link
Member

@TomasVotruba TomasVotruba commented Jan 26, 2026

In some cases, there is a mock variable just for its sake. Never mocked, never used.
This might seem little deal, but is a big deal to PHPUnit 12 and less code to read by human & AI.

Instead, we can inline it directly:

-$someMock = $this->createMock(SomeClass::class);
-$anoterMock = $this->createMock(AnotherClass::class);

$realObject = new RealObject(
-    $someMock,
+    $this->createMock(SomeClass::class),
-    $anotherMock,    
+    $this->createMock(AnotherClass::class),
);

Works great with #608 🎉 to remove your PHPUnit notices


Result from real Project

  • 900 lines gone 👌
Screenshot From 2026-01-26 17-40-59

@TomasVotruba TomasVotruba changed the title tv assign single use direct [code-quality] Add BareCreateMockAssignToDirectUseRector Jan 26, 2026
@TomasVotruba TomasVotruba force-pushed the tv-assign-single-use-direct branch 3 times, most recently from 73da547 to b7aa5a4 Compare January 26, 2026 14:23
@TomasVotruba TomasVotruba force-pushed the tv-assign-single-use-direct branch from b7aa5a4 to f7813ed Compare January 26, 2026 14:23
@TomasVotruba TomasVotruba merged commit 7a318b2 into main Jan 26, 2026
7 checks passed
@TomasVotruba TomasVotruba deleted the tv-assign-single-use-direct branch January 26, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants